Conversion Using Linux

How to convert your chart images to a format that OpenCPN will read using Linux

Do you have a bunch of scanned charts of your area, in graphical format (jpg, tiff, etc.) and OpenCPN won't read them?
Here's how you can – with a bit of work, sure, but worth the effort – convert them into usable electronic charts.

The tools:

  1. ImageMagick: http://www.imagemagick.org/ (Binary releases are available for a few distributions, for Ubuntu just get it with the package manager, it's in the repositories.)
  2. Libbsb: http://libbsb.sourceforge.net (You will need some version of libtiff-dev and libpng-dev installed to build it. A .deb package that worked fine for me can be found at libBSB.
  3. mc2bsbh: you can get it here.
    1. Get the c++ source file, and from its directory, type:
    2. g++ -Wall -s -O2 mc2bsbh.cpp -o mc2bsbh
    3. It compiled without any problem on my (very standard) Karmic. I personally put it in /usr/local/bin, which I own as user, so it's in the PATH and can be called from anywhere, if you leave it in the working directory, use ./mc2bsbh
  4. MapCal: part of the free navigation package SeaClear .
    1. Note: I had some problems running it with Wine (saving the calibration) but I can't reproduce the error and now it works fine. One suggestion is, make the directory you're going to write the calibration in world-writable before running MapCal.
  5. The pcx2tif script (optional) , found pcx2tif.zip here. This is a great little shell script by “taifun” used to convert old Maptech-style formats of tiled charts. If you find your chart is made of little bits instead of a whole file, this will stitch them all together in TIFF format.
    1. Instructions for use are in the tarball.

Once we have the tools all set up, we can get to work. The process in in five steps:

  1. Convert a chart image to tiff with imagemagick.
  2. Convert it again to png with the same (you'll need both files).
  3. Load the png version of the chart in Mapcal and calibrate it.
  4. Generate the chart header with mc2bsbh, and make the .kap version of the chart, with libbsb.
  5. Copy the resulting .kap into opencpn's chart dir, and reload the chart database.

Let's see them in detail:

Steps 1 and 2:

Say you have a chart in jpeg format called chart.jpg.

From the command line, use:
convert chart.jpg -colors 127 chart.gif

and then again,
convert chart.gif -colors 127 chart.tif

and then again,
convert chart.jpg -colors 127 chart.png

(there is a script that does this for multiple files, get it here , just remove the .doc extension, this is the example)
Throw away the .gif file. Don't ask me why you need to generate it in the first place, but apparently you do, it's an imagemagick thing. Keep the .tif and the .png ones a while longer, though. You'll be even happier to get rid of them when you've finished.

Step 3:

Step 4:

Note 1: you can also make the .hdr file “manually”, using a template and entering the calibration data with a text editor, but I won't go into that for the moment.

Note 2 (about the commands, so if there's any problem you know what to look for) :

  1. convert is a command from imagemagick.
    tif2bsb is a command from libbsb.
    mc2bsbh is a standalone thing.

Note 3: (by Jonasberg, on the colors in the conversions) :

  1. The “127” is the number of individual colors used. Sometimes it pays of to reduce this number to get a smaller file size, say, if you start with a bitmapped format like png that contains fewer colors.

Note 4: On the joinpcx script:

If you use it “standalone” and not as part of the “charts” script, change the lines,
convert new1.gif - colors 127 $1.tif
(and .png) to
convert new1.gif -colors 127 `basename $PWD`.tif
(and .png)
because the “$1” will not create files with [directory_name].tif and .png, it won't create any files at all.
Using `basename $PWD`will make files called [current directory name].tif (and .png).
So just edit the script to whatever suits you best.